package com.shijie.controller.app;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shijie.core.Result;
import com.shijie.core.ResultGenerator;
import com.shijie.domain.entity.Brands;
import com.shijie.domain.enums.EnumInterface;
import com.shijie.service.BrandsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/*
 *  商品品牌相关接口
 *
 *  @author: smart boy
 *  @date: 2018-08-06
 */
@RestController
@RequestMapping("/app/brands")
public class AppBrandsController {

	@Resource
	private BrandsService brandsService;

    @GetMapping("search")
    public Result search(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                         @RequestParam String q) {
        PageHelper.startPage(page, pageSize);

        List<Brands> list = brandsService.list(q, EnumInterface.Status.VALID.ordinal());
        PageInfo<Brands> pageInfo = new PageInfo<>(list);
        return ResultGenerator.success(pageInfo);
    }

	@GetMapping
	public Result list() {
        List<Brands> list = brandsService.list(null, EnumInterface.Status.VALID.ordinal());
        return ResultGenerator.success(list);
    }


	@GetMapping("/{id}")
	public Result detail(@PathVariable Integer id) {
		Brands brands = brandsService.selectById(id);
		return ResultGenerator.success(brands);
	}
}

